using System;
using System;
using System.Runtime.InteropServices;
using System.IO;

namespace rudp
{
	public struct MessageReceipt
	{
		public byte   Count;
		public byte[] MessagesNotReceived;

		public byte[] ToByteArray ()
		{
			byte[] data = new byte[ Count + 1 ];

			using (MemoryStream stream = new MemoryStream( data )) 
			{
				BinaryWriter writer = new BinaryWriter(stream);
				writer.Write( Count );

				if( MessagesNotReceived != null && MessagesNotReceived.Length > 0 )
					writer.Write( MessagesNotReceived );
			}

			return data;
		}

		public void FromByteArray (byte[] data)
		{
			using (MemoryStream stream = new MemoryStream( data )) 
			{
				BinaryReader reader = new BinaryReader (stream);

				this.Count = reader.ReadByte();
				this.MessagesNotReceived = reader.ReadBytes( this.Count );
			}
		}
	}
}

